package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sg.hms.Model.Role;
import com.sg.hms.Model.User;
import com.sg.hms.Service.Funcservice;
import com.sg.hms.ServiceImpl.FuncserviceImpl;

import net.sf.json.JSONArray;
/**
 * 
 * @author 王奇霞
 *
 */
public class ShowfuncsController extends HttpServlet{
    Funcservice fservice=new FuncserviceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	JSONArray funcs=new JSONArray();
    	HttpSession session=req.getSession();
    	User user=(User)session.getAttribute("currentUser");
    	Role role=(Role)session.getAttribute("currentrole");
    	funcs=fservice.findFuncsByParentId(-1,role.getfItem());
    	//System.out.println(role.getfItem());
    	resp.setCharacterEncoding("utf8");
	    PrintWriter  pw  =  resp.getWriter();
	     
	   //System.out.println(funcs.toString());
	     pw.write(funcs.toString());
    }
   
}
